<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<title>配送比例</title>
<jsp:include page="../../include/header.jsp"></jsp:include>
<style type="text/css">
table th {
	text-align: center;
}

table td {
	text-align: center;
}

table {
	empty-cells: show;
	border-collapse: collapse;
	margin: 0 auto;
}

.col-lg-9 {
	width: 100%;
}

.pcc {
	width: 110px;
	height: 34px;
}

input {
	text-indent: 10px;
	border-radius: 5px;
}
/*排序 */
.querySort {
	position: relative;
}

.down {
	position: absolute;
	top: 12px;
	display: inline-block;
	width: 10px;
	height: 12px;
	margin-left: 8px;
	background: url("${BASE_PATH}/static/images/sprite-arrow.png") 0 61px;
}

.sort .querySort:NTH-OF-TYPE(2) .down {
	top: -3px;
	transform: rotateX(180deg);
}

.querySort:hover .down {
	background: url("${BASE_PATH}/static/images/sprite-arrow.png") 0 21px;
}

.downSort {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 24px;
	opacity: 0;
	cursor: pointer;
}

.upSort {
	position: absolute;
	top: -15px;
	left: 3px;
	width: 18px;
	height: 24px;
	opacity: 0;
	cursor: pointer;
}
</style>
</head>
<body>
	<div id="wrapper" class="row">
		<div class="col-lg-12">
			<h1 class="page-header">配送比例</h1>
		</div>
	<!-- 搜索框 -->
	<div class="title-top col-lg-12">
		
	    
    	<label class="search-label">录入转换比例：</label>
			<input type="text" id="sNum" value="" placeholder="转换一次所需惠券" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" class="form-control search-input width200" maxlength="21">
		<label class="search-label">日期：</label>
		<div class="search-input" >
        	<select id="sType" class="selectpicker" data-width="150">
				<option value="1">今天</option>
				<option value="2">昨天</option>
			</select>
        </div>	
		<button  class="btn btn-success margin-lr" onclick="toAdd();">添加</button>	
		<%-- <shiro:hasPermission name="bus:user:jifen:doExcel">
			<button onclick="doExcel();" class="btn btn-success pull-right">导出</button>
		</shiro:hasPermission> --%>
			
	</div>
		<div class="col-lg-12 title-top">
			<div class="col-lg-12">
				<div class="text-muted single-line-text pull-left">
					共 <font color="#428bca" id="dataCount">0</font> 条记录
				</div>
			</div>
			<div class="table-responsive panel panel-default">
				<table id="dataTable" class="table table-hover table-bordered"
					style="overflow: scroll;">
					<thead>
						<tr>
							<th width="200px;">日期</th>
							<th width="350px;">比例值</th>
							<th width="150px;">添加时间</th>
							<th width="150px;">操作</th>
							
						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</div>
			<div class="col-lg-12">
				<ul id="dataPagination" class="pagination-sm pull-right"></ul>
			</div>
		</div>

	</div>
	<jsp:include page="../../include/javascripts.jsp"></jsp:include>
	<!-- 异步加载下一页数据后，用模板渲染 -->
	<script type="text/html" id="dataTpl">
		{{each list as item i}}
				 <tr id="item{{item.id}}" data-id="{{item.id}}">
					<td>{{item.date }}</td>
					<td>
						{{item.scaleValue}}
					</td>
					<td>{{item.createDate}}</td>
					{{if i<3}}
						<td>
							<a href="javascript:toUpdate('{{item.id}}');"><span class="btn">编辑</span></a>
						</td>
					{{/if}}
					{{if i>2}}
						<td>
							<a href="javascript:return false" style="opacity: 0.3"><span class="btn">编辑</span></a>
						</td>
					{{/if}}
				</tr>
		{{/each}}
</script>
	<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	 var params = {
		pageSize:10,
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/change/scale/pageScale",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}
/*修改*/
var viewDialog;
function toUpdate(id){
    viewDialog = Kit.dialog("修改","${BASE_PATH}/change/scale/toUpdate?id="+id,{closable:true}).open();
}


/*添加配送比例*/
var viewDialog;
function toAdd(){
    var num=$("#sNum").val(),type=$("#sType").val();
   
    if(num == '' || num == undefined || num == null){
    	Kit.alert("请录入转换比例");
    }else{
    	$.post("${BASE_PATH}/change/scale/toAdd?scaleValue="+num+"&date="+type,function(result){
    		if(result.flag==-1){
    			Kit.alert(result.message);
    		}else{
    			query();
    		}
			
		});
    }
}
/* 重置查询条件 */
function reset(){
	$("#sNum").val("");
	$("#sType").val("");$("#sType").trigger("change");
}
function onEditSuccess(newObject){
	$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
}
function doExcel(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),store=$("#sStore").val();
	window.location.href="${BASE_PATH}/change/delivery/doExcel?phone="+phone+"&card="+card+"&store="+store;
}
function doDeliveryExcel(){
	var adIds = "";
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(i==0){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    var num=$("#sNum").val(),type=$("#sType").val();
   
    if(adIds == ""){
    	Kit.alert("请选择要转换的人员");
    }else if(num == '' || num == undefined || num == null){
    	Kit.alert("请录入转换比例");
    }else{
    	window.location.href="${BASE_PATH}/change/delivery/doDeliveryExcel?adIds="+adIds+"&num="+num+"&type="+type;
    }
} 
//订单量、收藏量、浏览量  单选图片点击切换
var querySort=document.getElementsByClassName("querySort");//点击区域
var down=document.getElementsByClassName("down");
for(var i=0;i<querySort.length;i++){
	   //给每个class添加id标识(当索引)区分每个class
	   querySort[i].id=i;	   
	   //鼠标点击改变背景图片偏移
	   querySort[i].onclick=function(){
		   //当前索引
		   var index=this.id;
		   for( j=0;j<down.length;j++){
			   down[j].style.backgroundPosition="0px 61px";
		   }
		 //改变索引为当前的class背景图片偏移位置
		   down[index].style.backgroundPosition="0px 21px";
	   }
}
//异步取营业部的值
$("#sSeller").change(function(){
	sSeller=$("#sSeller").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/change/delivery/chooseStore",
           data: {"seller" : sSeller},
           dataType: "json",
           traditional: true,
           success: function(data){
			$("#sStore").empty(); 
			$("#sStore").append("<option value=''>请选择营业部</option>");
			for(var i=0; i<data.object.length;i++){
				$("#sStore").append("<option value='"+data.object[i].storeid+"'>"+data.object[i].title+"</option>");
               }
              // $("#toBossOneId").selectpicker("refresh");	
           }
       });
    });
$("#sStore").change(function(){
	sStore=$("#sStore").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/change/delivery/chooseDao",
           data: {"store" : sStore},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#sDao").empty(); 
               $("#sDao").append("<option value=''>请选择营业部</option>");
               for(var i=0; i<data.object.length;i++){
              	 $("#sDao").append("<option value='"+data.object[i].trueName+"'>"+data.object[i].trueName+"</option>");
               }
              	//$("#sDao").selectpicker("refresh");
           }
       });
    });
 /* 选择需要转换的会员 */
/* var toViewDialog;
function toView(){
	var adIds = "";  
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(i==0){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    if(adIds==""){
    	Kit.alert("请选择要转换的人员");
    }else{
  		 messageDialog=Kit.dialog("转换预览","${BASE_PATH}/change/delivery/toView/"+adIds,{size:'size-wide',closable:true}).open();
    }
} */

 
</script>
</body>
</html>